import 'package:flutter/material.dart';
import '../home.dart';
import '../hot_spot.dart';
import '../misson.dart';
import 'animated_bottom_bar.dart';


class BottomBarNavigationPatternExample extends StatefulWidget {
  final List<BarItem> barItems = [
    BarItem(
      text: "热点推送",
      iconData: Icons.search,
      color: Colors.indigo,
    ),
    BarItem(
      text: "任务",
      iconData: Icons.account_balance_wallet_outlined,
      color: Colors.pinkAccent,
    ),
    BarItem(
      text: "主页",
      iconData: Icons.person_outline,
      color: Colors.orangeAccent,
    ),
  ];

  @override
  _BottomBarNavigationPatternExampleState createState() =>
      _BottomBarNavigationPatternExampleState();
}

class _BottomBarNavigationPatternExampleState
    extends State<BottomBarNavigationPatternExample> {
  int selectedBarIndex = 0;

  int currentIndex=0;

  final pages = [HotSpotPage(), MissionPage(), HomePage()];

  @override
  void initState() {
    super.initState();
    currentIndex = 0;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: null,
      bottomNavigationBar: AnimatedBottomBar(
        barItems: widget.barItems,
        animationDuration: const Duration(milliseconds: 150),
        barStyle: BarStyle(
          fontSize: 20.0,
          iconSize: 30.0,
        ),
        onBarTap: (index) {
          setState(() {
            selectedBarIndex = index;
            currentIndex = index; // 更新当前索引以切换页面
          });
        },
      ),
      body: pages[currentIndex],
    );
  }
}
